﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;


namespace KunURP.Editor
{
    public class KunSubDrawer : MaterialPropertyDrawer
    {
        public string Group { get; private set; }
        public bool IsShow {
            get
            {
                if (ShaderDrawUtility.HaveGroup(this.Group))
                {
                    return ShaderDrawUtility.CheckGroupIsShow(this.Group);
                }
                return true;
            }
        }
        private float m_Height = 0;
        public KunSubDrawer() : this("") {}
        public KunSubDrawer(string group)
        {
            this.Group = group;
        }

        public override void OnGUI(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor)
        {
            this.m_Height = position.height;
            if (!ShaderDrawUtility.HaveGroup(this.Group))
            {
                this.DrawShaderProperty(position, prop, label, editor);
                return;
            }
            bool show = ShaderDrawUtility.CheckGroupIsShow(this.Group);
            if (show)
            {
                EditorGUI.indentLevel++;
                this.DrawShaderProperty(position, prop, label, editor);
                EditorGUI.indentLevel--; 
            }
        }

        public override float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor)
        {
            return this.IsShow ? this.m_Height : 0; 
        }

        public virtual void DrawShaderProperty(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor)
        {
            editor.DefaultShaderProperty(prop, label.text);
        }
    }
}
